"use strict";
const Generator = require("yeoman-generator");
const yosay = require("yosay");

module.exports = class extends Generator {
  prompting() {
    // Have Yeoman greet the user.
    this.log(yosay(`欢迎使用 LayaAir 模板生成器!`));

    const prompts = [];

    return this.prompt(prompts).then(props => {
      // To access props later use this.props.someAnswer;
      this.props = props;
    });
  }

  writing() {
    this.log("创建项目中...\n");

    this.__writingCopy(
      [
        ".laya",
        "bin",
        "env",
        "laya",
        "libs",
        "source",
        "src",
        ".prettierrc",
        "index.html",
        "package.json",
        "README.md",
        "tsconfig.json",
        "vite-template.laya",
        "vite.config.js"
      ],
      this.props
    );
    this.fs.copyTpl(
      this.templatePath(".gitignore_temp"),
      this.destinationPath(".gitignore")
    );
  }

  __writingCopy(filePath, params) {
    filePath.forEach(item => {
      this.fs.copyTpl(
        this.templatePath(item),
        this.destinationPath(item),
        params
      );
    });
  }
};
